package com.ddone.demo.mapper;

import com.ddone.demo.bean.Emp;
import com.ddone.demo.utils.MybatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * @author ddone
 * @date 2024/3/18-23:07
 */

public class MybatisCacheTest {
    private SqlSession sqlSession;
    private EmpMapper mapper;

    @Before
    public void init() {
        sqlSession = MybatisUtil.openAutoSession();
        mapper = sqlSession.getMapper(EmpMapper.class);
    }
    @After
    public void destroy() {
        sqlSession.close();
    }
    @Test
    public void testCache(){
        Emp emp = mapper.selectEmpById(8);
        System.out.println(emp);
        System.out.println("----------------");
        //执行 mapper  DML方法
        //手动清空缓存
        // sqlSession.clearCache();
        //提交事务
        // sqlSession.commit(); //一个业务的完成，一级缓存的范围就是一个业务！ commit 内部调用 clearCache()
        System.out.println("----------------");

        Emp emp1 = mapper.selectEmpById(8);
        System.out.println(emp1);
    }



}
